<?php
header("Content-Type:application/json;charset=UTF-8");
$connt = mysqli_connect('localhost','root','root','admin');
if(!$connt)
{
    echo json_encode(['code'=>0,'msg'=>'连接失败']);
}
$sql = 'SELECT staff.name,count(*) as total
FROM `worker` join staff
on staff.dep_id = worker.dept_id
GROUP BY dep_id';


$query = mysqli_query($connt,$sql);
$data = mysqli_fetch_all($query,MYSQLI_ASSOC);

$sql1 = 'SELECT COUNT(sex) as value,sex as name from worker GROUP BY sex';
$query1 = mysqli_query($connt,$sql1);
$res = mysqli_fetch_all($query1,MYSQLI_ASSOC);

$sql2 = 'SELECT salary,year,time FROM salary where name = "蔡徐坤"';
$query2 = mysqli_query($connt,$sql2);
$zx = mysqli_fetch_all($query2,MYSQLI_ASSOC);

$xData = [];
$yData = [];
$zxData = [];
$zxData1 = [];
foreach ($data as $val)
{
    $xData[] = $val['name'];
    $yData[] = $val['total'];
}
foreach ($zx as $val)
{
    $zxData[] = $val['salary'];
    $zxData1[] = $val['time'].'.'.$val['year'];
}
if($data && $res)
{
    echo json_encode(['code'=>1,'msg'=>'返回数据','data'=>[
        'x'=>$xData,
        'y'=>$yData,
        'bt'=>$res,
        'zx'=>$zxData,
        'zx1'=>$zxData1
    ]]);
}